import subprocess

def demo():
    # 1. 创建测试 patch
    test_patch = """\
From: Boss <boss@example.com>
Date: Fri, 10 Oct 2025 12:00:00 +0800
Subject: 测试补丁

diff --git a/test.py b/test.py
index abc123..def456 100644
--- a/test.py
+++ b/test.py
@@ -0,0 +1,3 @@
+print("Hello World")
+print("这是第一部分")
+print("保留它")
@@ -0,0 +4,2 @@
+print("第二部分")
+print("丢弃它")
"""
    with open("test.patch", "w", encoding="utf-8") as f:
        f.write(test_patch)
    print("✅ 测试文件已创建: test.patch")

    # 2. 模拟用户选择（保留第1块，丢弃第2块）
    print("\n📝 用户选择: Y (保留) → N (丢弃)")
    result = subprocess.run(
        ["python", "git_patch_editor.py", "-i", "test.patch", "-o", "result.patch"],
        input="Y\nN\n",
        encoding="utf-8",
        capture_output=True
    )

    # 3. 输出结果
    print("\n" + "="*60)
    print("运行日志:")
    print("-"*60)
    print(result.stdout)
    
    if result.returncode == 0:
        print("\n" + "="*60)
        print("🎯 最终 result.patch 内容:")
        print("-"*60)
        with open("result.patch", "r", encoding="utf-8") as f:
            print(f.read())
        print("\n🎉 老板！工具终于成功了！没有依赖也能完美工作！")
    else:
        print("\n" + "="*60)
        print("❌ 错误详情:")
        print("-"*60)
        print(result.stderr)

if __name__ == "__main__":
    demo()